package interpreter

import (
	"errors"
	"fmt"
	"strings"
)

type SaleOrder struct {
	id *tIntField
	customer *tStringField
	city *tStringField
	product *tStringField
	quantity *tIntField
}

func NewSaleOrder(id int, customer string, city string, product string, quantity int) *SaleOrder {
	return &SaleOrder{
		id: newIntField("id", id),
		customer: newStringField("customer", customer),
		city: newStringField("city", city),
		product: newStringField("product", product),
		quantity: newIntField("quantity", quantity),
	}
}


func (me *SaleOrder) ID() int {
	return me.id.value
}

func (me *SaleOrder) Customer() string {
	return me.customer.value
}

func (me *SaleOrder) City() string {
	return me.city.value
}

func (me *SaleOrder) Product() string {
	return me.product.value
}

func (me *SaleOrder) Quantity() int {
	return me.quantity.value
}

func (me *SaleOrder) GetField(field string) (error,IDataField) {
	if strings.EqualFold(field, "ID") {
		return nil, me.id
	}

	if strings.EqualFold(field, "Customer") {
		return nil, me.customer
	}

	if strings.EqualFold(field, "City") {
		return nil, me.city
	}

	if strings.EqualFold(field, "Product") {
		return nil, me.product
	}

	if strings.EqualFold(field, "Quantity") {
		return nil, me.quantity
	}

	return errors.New("no such field"), nil
}

func (me *SaleOrder) String() string {
	return fmt.Sprintf("id=%v, customer=%v, city=%v, product=%v, quantity=%v", me.ID(), me.Customer(), me.City(), me.Product(), me.Quantity())
}